<?php

/**
 * 用户邀请记录表
 */

namespace App\Models\MainDB\Shareprize;

use Illuminate\Database\Eloquent\Model;

class ShareprizeUserRecord extends Model
{

    protected $table = 'ln_shareprize_user_record';     //数据库内完整表名

    protected $primaryKey = 'id';    //主键名

    protected $fillable = [
        "id",
        "share_user_id",
        "share_code",
        "register_user_id",
    ];

    public $timestamps = false;

    public function list($uid, $params)
    {

        $where[] = ['a.share_user_id', '=', $uid];
        $list = app('model_shareprize_user_record')
            ->from('ln_shareprize_user_record as a')
            ->join('ln_user_data as b', 'a.register_user_id', '=', 'b.user_id')
            ->leftJoin('ln_user as c', 'a.register_user_id', '=', 'c.user_id')
            ->select([
                'c.user_id', 'b.user_code', 'b.head_picture', 'b.nickname', 'b.sex', 'c.nobility', 'c.rank_id',
                'a.created_at'
            ])
            ->where($where)
            ->orderBy('a.id', 'desc')
            ->paginate($params['page_size'], ['*'], '', $params['page']);

        return $list;
    }
}
